home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kxerrorhandler.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  4.5 KB  |  105 lines

  1. /*
  2.  
  3.   Copyright (c) 2003 Lubos Lunak <l.lunak@kde.org>
  4.  
  5.   Permission is hereby granted, free of charge, to any person obtaining a
  6.   copy of this software and associated documentation files (the "Software"),
  7.   to deal in the Software without restriction, including without limitation
  8.   the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9.   and/or sell copies of the Software, and to permit persons to whom the
  10.   Software is furnished to do so, subject to the following conditions:
  11.  
  12.   The above copyright notice and this permission notice shall be included in
  13.   all copies or substantial portions of the Software.
  14.  
  15.   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16.   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17.   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  18.   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19.   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20.   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21.   DEALINGS IN THE SOFTWARE.
  22.  
  23. */
  24.  
  25. #ifndef KXERRORHANDLER_H
  26. #define KXERRORHANDLER_H
  27.  
  28. #include <qvaluelist.h>
  29. #include <qwindowdefs.h>
  30. #include <kdelibs_export.h>
  31. #include <X11/Xlib.h>
  32.  
  33. /**
  34.  * This class simplifies handling of X errors. It shouldn't be necessary to use
  35.  * with Qt classes, as the toolkit should handle X errors itself, so this
  36.  * class will be mainly used with direct Xlib usage, and some lowlevel classes
  37.  * like NETWinInfo.
  38.  *
  39.  * The usual usage is to create a KXErrorHandler instance right before starting
  40.  * operations that might cause X errors, and checking if there was an error
  41.  * by calling error() after the operations are finished. The handlers
  42.  * may be nested, but must be destroyed in reverse order they were created.
  43.  *
  44.  * There's no need to do X sync before creating an instance, every instance
  45.  * will handle only errors for request issued after the instance was created.
  46.  * Errors for older requests will be passed to previous error handler.
  47.  * When checking for error by calling error() at the end, it is necessary
  48.  * to sync with X, to catch all errors that were caused by requests issued
  49.  * before the call to error(). This can be done by passing true to error()
  50.  * to cause explicit XSync(), however, if the last X request needed a roundtrip
  51.  * (e.g. XGetWindowAttributes(), XGetGeometry(), etc.), it is not required
  52.  * to do an explicit sync.
  53.  *
  54.  * @author Lubos Lunak <l.lunak@kde.org>
  55.  * @short Handler for X errors
  56.  */
  57. class KDECORE_EXPORT KXErrorHandler
  58.     {
  59.     public:
  60.         /**
  61.          * Creates error handler that will set error flag after encountering
  62.          * any X error.
  63.          */
  64.         KXErrorHandler( Display* dpy = qt_xdisplay());
  65.         /**
  66.          * This constructor takes pointer to a function that will get request number,
  67.          * error code number and resource id of the failed request, as provided
  68.          * by XErrorEvent. If the function returns true, the error flag will be set.
  69.          */
  70.         KXErrorHandler( bool (*handler)( int request, int error_code, unsigned long resource_id ), Display* dpy = qt_xdisplay());
  71.         /**
  72.          * This constructor takes pointer to a function whose prototype matches
  73.          * the one that's used with the XSetErrorHandler() Xlib function.
  74.          * NOTE: For the error flag to be set, the function must return non-zero
  75.          * value.
  76.          */
  77.         KXErrorHandler( int (*handler)( Display*, XErrorEvent* ), Display* dpy = qt_xdisplay());
  78.         /**
  79.          * This function returns true if the error flag is set (i.e. no custom handler
  80.          * function was used and there was any error, or the custom handler indicated
  81.          * an error by its return value).
  82.          *
  83.          * @param sync if true, and explicit XSync() will be done. Not necessary
  84.          *             when the last X request required a roundtrip.
  85.          */
  86.         bool error( bool sync ) const;
  87.         ~KXErrorHandler();
  88.     private:
  89.         void addHandler();
  90.         int handle( Display* dpy, XErrorEvent* e );
  91.         bool (*user_handler1)( int request, int error_code, unsigned long resource_id );
  92.         int (*user_handler2)( Display*, XErrorEvent* );
  93.         int (*old_handler)( Display*, XErrorEvent* );
  94.         unsigned long first_request;
  95.         Display* display;
  96.         bool was_error;
  97.         static int handler_wrapper( Display*, XErrorEvent* );
  98.         static KXErrorHandler** handlers;
  99.         static int pos;
  100.         static int size;
  101.         class KXErrorHandlerPrivate* d;
  102.     };
  103.  
  104. #endif
  105.